package com.abei.gas.controller;

import com.abei.gas.entity.Admin;
import com.abei.gas.service.AdminService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin")
@Api(tags = "管理员相关接口")
public class AdminController {
    @Autowired
    AdminService adminService;
    Map<String,Object> map = new HashMap<>();

    @RequestMapping("/login")
    public Map<String,Object> login(@RequestBody Admin admin){
        map.clear();
        String id = admin.getUsername();
        String password = admin.getPassword();
        System.out.println(id);
        System.out.println(password);
        Integer login = adminService.Login(id, password);
        System.out.println(login);
        if(login==0) {
            map.put("msg", "1");
        }
        if(login==1) {
            map.put("msg", "用户名不存在！");
        }
        if(login==2) {
            map.put("msg","密码错误");
        }
        return map;
    }
    @RequestMapping("/select")
    public Map<String,Object> select(@RequestBody Admin admin){
        map.clear();
        String username=admin.getUsername();
        Integer insert = adminService.Select(username);
        if(insert==1)
            map.put("msg","1");
        if(insert==0)
            map.put("msg","0");
        return map;
    }
    @RequestMapping("/insert")
    public Map<String,Object> insert(@RequestBody Admin admin){
        map.clear();
        String username=admin.getUsername();
        String password=admin.getPassword();
        Integer insert = adminService.insert(username, password);
        if(insert==1)
            map.put("msg","1");
        return map;
    }
}
